/**
 * 
 */
package com.gopay.bis.ceb.ebank.operation;

import com.csii.payment.client.core.CebMerchantSignVerify;
import com.gopay.bis.common.util.BankLogUtils;
import com.gopay.common.constants.proccode.ProcCodeConstants;
import com.gopay.common.domain.bank.BaseMessage;
import com.gopay.common.domain.bank.ceb.ebank.CebB2bMessage;
import com.gopay.common.exception.GopayException;
import com.gopay.remote.bank.ICertHelper;

/**
 * @CebB2bCertHelper.java
 * @author Ryan
 * @2013-12-3 上午9:47:33  www.gopay.com.cn Inc.All rights reserved.
 */
public class CebB2bCertHelper implements ICertHelper {
    
    @Override
    public String sign(BaseMessage baseMessage) throws GopayException {
        String signMsg=null;
        try {
        	CebB2bMessage message = (CebB2bMessage)baseMessage;
            BankLogUtils.printB2BSignPlainLog(message);
            signMsg = CebMerchantSignVerify.merchantSignData_ABA(message.getPlainMessage());
            baseMessage.setSignMessage(signMsg);
            BankLogUtils.printB2BSignSignatureLog(baseMessage, signMsg);
            return signMsg;
        } catch (Exception e) {
            BankLogUtils.printB2CSignExceptionLog(baseMessage, e);
            throw new GopayException(ProcCodeConstants.PROC_CODE_100E6028);
        }
    }

    @Override
    public Object verify(BaseMessage baseMessage) throws GopayException {
        boolean isVerfy=false;
        try {
        	CebB2bMessage message = (CebB2bMessage)baseMessage;
            BankLogUtils.printB2BVerifyPlainLog(message);
            isVerfy = CebMerchantSignVerify.merchantVerifyPayGate_ABA(message.getSignMessage(), baseMessage.getPlainMessage());
            BankLogUtils.printB2BVerifyResultLog(message, isVerfy);
            return isVerfy;
        } catch (Exception e) {
            BankLogUtils.printB2CSignExceptionLog(baseMessage, e);
            throw new GopayException(ProcCodeConstants.PROC_CODE_100E6030);
        }
    }

}
